﻿using DevTeam;
using System;
using System.Collections.Generic;
using System.Data;

//DESTEX.yeni
namespace ConfExpert.Forms.ImportWizards.Stok
{
    public partial class Destex_LTH_Tip2 : XITopCekiListesi
    {
        int YuklemeId;
        public Destex_LTH_Tip2(int YuklemeId) :
            base(YuklemeId)
        {
            InitializeComponent();

            this.YuklemeId = YuklemeId;
            this.Init("Destex LTH Tip2 Top Listesi", true);
            this.FileDone += Destex_LTH_Tip2_FileDone;

            btnSave.Enabled = false;
            splitter.AutoSize();
        }

        void Destex_LTH_Tip2_FileDone(DataSet Data, string FileName)
        {
            DataTable dt = Data.Tables[0];
            DataRowCollection rows = dt.Rows;
            DataColumnCollection cols = dt.Columns;

            Dictionary<string, int> indexes = new Dictionary<string, int>();

                DataRow dr0 = dt.Rows[1];
                for (int colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
                {
                    switch (dr0[colIndex].ToString())
                    {
                        //DO NO. 	LUTHAI NO	PATTERN NO	CONSTRUCTION	ROLL	COLOUR	TICKET	ACTUAL	ACTUAL

                        case "PATTERN NO": indexes.Add("Article", colIndex); break;
                        case "CONSTRUCTION": indexes.Add("VendorConstruction", colIndex); break;
                        case "ROLL": indexes.Add("VendorRollId", colIndex); break;
                        case "COLOUR": indexes.Add("LotNo", colIndex); break;
                        case "ACTUAL":
                            if (!indexes.ContainsKey("WidthUsable"))
                                indexes.Add("WidthUsable", colIndex);
                            break;
                        case "LENGTH":
                            if (!indexes.ContainsKey("Qty"))
                                indexes.Add("Qty", colIndex);
                            break;

                    }
                }



            for (int i = 2; i < dt.Rows.Count; i++)
            {
                DataRow dr = rows[i];
                if (dr[indexes["Article"]] != DBNull.Value)
                {
                    string patternNo = dr[indexes["Article"]].ToStr();

                    if (Article.Select("Article='" + patternNo + "'").Length == 0)
                    {
                        DataRow drArticle = Article.NewRow();
                        if (indexes.ContainsKey("Article"))
                            drArticle["Article"] = patternNo;
                        if (indexes.ContainsKey("VendorConstruction"))
                            drArticle["VendorConstruction"] = dr[indexes["VendorConstruction"]];
                        Article.Rows.Add(drArticle);
                    }

                    DataRow drRoll = Roll.NewRow();
                    if (indexes.ContainsKey("Article"))
                        drRoll["Article"] = patternNo;
                    if (indexes.ContainsKey("VendorRollId"))
                        drRoll["VendorRollId"] = dr[indexes["VendorRollId"]];
                    if (indexes.ContainsKey("LotNo"))
                        drRoll["LotNo"] = dr[indexes["LotNo"]];
                    if (indexes.ContainsKey("WidthActual"))
                        drRoll["WidthActual"] = dr[indexes["WidthActual"]];
                    if (indexes.ContainsKey("WidthUsable"))
                        drRoll["WidthUsable"] = dr[indexes["WidthUsable"]];
                    drRoll["Qty"] = dr[indexes["Qty"]];
                    Roll.Rows.Add(drRoll);
                }
            }
        }



    }
}
